package com.activities;


import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.Listeners.MenuClickListener;
import com.Listeners.MenuMineClickListener;
import com.SoapClasses.SoapUtil;
import com.TextFormat.UtilFonts;
import com.activities.ActivityMenu.Item;
import com.activities.ActivityMenuMine.iconTextArrayAdapter.RowType; // $codepro.audit.disable unnecessaryImport
import com.shareup.R;


public class ActivityMenuMine extends ListFragment {

    public static int SELECTED_MENU_START = SoapUtil.MODE_NEWS;

    public boolean popularPending = false;

    private iconTextArrayAdapter adapter;
  

    private List<Item> items;

  
  
    private View v;

    //
    public static class Header implements Item {

        private final String name;

        public Header(String name) {

            this.name = name;
        }

        @Override
        public View getView(LayoutInflater inflater, View convertView) {

            View view;
            TextView text = null;
            if (convertView == null) {
                view = inflater.inflate(R.layout.item_menu_header, null);

            }
            else {
                view = convertView;
            }
            text = (TextView) view.findViewById(R.id.item_menu_header_text);
            UtilFonts.setTextBoldFont(text);
            text.setText(name);
            view.setTag(MenuClickListener.ITEM_TYPE_HEADER);

            return view;
        }

        @Override
        public int getViewType() {

            return RowType.HEADER_ITEM.ordinal();
        }
    }

    public static class iconTextArrayAdapter extends ArrayAdapter<Item> {

        private final LayoutInflater mInflater;

        public enum RowType {
            HEADER_ITEM, LIST_ITEM
        }

        public iconTextArrayAdapter(Context context, List<Item> items) {

            super(context, 0, items);
            mInflater = LayoutInflater.from(context);
        }

        @Override
        public int getItemViewType(int position) {

            return getItem(position).getViewType();
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            return getItem(position).getView(mInflater, convertView);
        }

        @Override
        public int getViewTypeCount() {

            return RowType.values().length;
        }
    }

    // //////////////////////////////////////////////////////////////////
    public static interface Item {

        public View getView(LayoutInflater inflater, View convertView);

        public int getViewType();
    }

    public static class ListItem implements Item {

        private final int iconRes;

        private final String text;

        private final int type;

        // private boolean wasHigh = false;

        public ListItem(String text1, int iconRes, int type) {

            this.text = text1;
            this.iconRes = iconRes;
            this.type = type;
        }

        @Override
        public View getView(LayoutInflater inflater, View convertView) {

            View view;
            if (convertView == null) {
                int resource = R.layout.item_menu;

                view = inflater.inflate(resource, null);
                // Do some initialization
            }
            else {
                view = convertView;
            }
            //
            TextView text1 = (TextView) view.findViewById(R.id.row_m_title);
            UtilFonts.setTextRegularFont(text1);
            ImageView icon = (ImageView) view.findViewById(R.id.row_icon);
                     
            text1.setText(text);
            icon.setImageResource(iconRes);
            view.setTag(type);

            if (type == SoapUtil.MODE_NEWS) {
                MenuClickListener.currentSelectedView = view;
                MenuClickListener.highlightCurrentRow(view);
            }
            return view;
        }

        @Override
        public int getViewType() {

            return RowType.LIST_ITEM.ordinal();
        }
    }

   
   

    @Override
    public void onActivityCreated(Bundle savedInstanceState) {

        super.onActivityCreated(savedInstanceState);

        inicializar();
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        v = inflater.inflate(R.layout.activity_menu_mine, null);
        return v;
    }

  

    private void addItemsMenu() {

       	  String[] arraymenu = this.getResources().getStringArray(R.array.myplaces);
       	  items = new ArrayList<Item>();
          items.add(new Header(arraymenu[0]));
          items.add(new ListItem(arraymenu[1], R.drawable.search_white,MenuMineClickListener.MINE_SEARCH));
          items.add(new ListItem(arraymenu[2], R.drawable.album_light, MenuMineClickListener.MINE_ALBUMS));
          items.add(new ListItem(arraymenu[3], R.drawable.add_tag_icon, MenuMineClickListener.MINE_TAGS));
        
          adapter = new iconTextArrayAdapter(getActivity(), items);
          setListAdapter(adapter);
          
          this.getListView().setOnItemClickListener(new MenuMineClickListener(getActivity()));

    }
    private void addItemsUpload() {

        String[] arraymenu = this.getResources().getStringArray(R.array.upload_menu);
        items = new ArrayList<Item>();
        items.add(new Header(arraymenu[0]));
        items.add(new ListItem(arraymenu[1], R.drawable.add_comment_icon,MenuMineClickListener.UPLOAD_COMMENT));
        items.add(new ListItem(arraymenu[2], R.drawable.add_location_icon_normal,MenuMineClickListener.UPLOAD_LOCATION));
        items.add(new ListItem(arraymenu[3], R.drawable.add_tag_icon, MenuMineClickListener.UPLOAD_TAGS));
        items.add(new Header(arraymenu[4]));
        items.add(new ListItem(arraymenu[5], R.drawable.album_light, MenuMineClickListener.UPLOAD_ALBUM));
        items.add(new Header(arraymenu[6]));
        items.add(new ListItem(arraymenu[7], R.drawable.shared_light, MenuMineClickListener.UPLOAD_PRIVACY));
        adapter = new iconTextArrayAdapter(getActivity(), items);
        setListAdapter(adapter);
        
        this.getListView().setOnItemClickListener(new MenuMineClickListener(getActivity()));

  }

    private void inicializar() {
            
       if(this.getActivity().getClass().toString().equals(ActivityUpload.class.toString()))
    	   addItemsUpload();
       else
    	   addItemsMenu();
    	   
    }

   

}
